#pragma once

#include <Direct3DResource.h>

// DirectX 头文件
#include <dxgi1_3.h>
#include <d2d1_3.h>
#include <d2d1_3helper.h>
#include <dcomp.h>
#include <memory>

namespace DirectXCore
{
	class D2DRenderer
	{
	private:
		HWND mWindowHandle;
		std::unique_ptr<D2D1_BITMAP_PROPERTIES1> mTargetBitmapProperties;

		// DXGI 相关
		ComPtr<IDXGISurface2> mDXGISurface;
		ComPtr<IDXGISwapChain1> mSwapChain;

		// D2D 相关
		ComPtr<ID2D1Device1> mD2DDevice;
		ComPtr<ID2D1Factory2> mD2DFactory;
		ComPtr<ID2D1DeviceContext> mD2DContext;
		ComPtr<ID2D1Bitmap1> mTargetBitmap;

		// DirectComposition
		ComPtr<IDCompositionDevice> mCompositionDevice;
		ComPtr<IDCompositionTarget> mCompositionTarget;
		ComPtr<IDCompositionVisual> mRootCompositionVisual;

		void InitRenderTarget();
		void InitD2DContext();
		void InitDirectComposition();

	public:
		D2DRenderer(HWND hWnd);
		~D2DRenderer();

		void Resize();
		void Render();

	protected:
		virtual void OnRender(ID2D1DeviceContext* dc);
	};
}